﻿function prepareTimepieceElements() {
if (prepareTimepieceElementsIsDone == false) {
for (i = 0; i < all_parts.length; i++) {
if (all_p[i]["update_mode"] == "monthdate" || all_p[i]["update_mode"] == "weekday") {
if (all_p[i]["url"] == null) {
var a = document.createElement("DIV")
} else {
var a = document.createElement("CANVAS")
}
document.getElementById("global_watch").appendChild(a);
if (typeof G_vmlCanvasManager != "undefined") {
a = G_vmlCanvasManager.initElement(a)
}
a.setAttribute("id", all_parts[i] + "_div");
a.style.position = "absolute";
a.style.width = all_p[i]["width"] + "px";
a.style.height = all_p[i]["height"] + "px";
a.style.left = all_p[i]["xoriginoffset"] + "px";
a.style.top = all_p[i]["yoriginoffset"] + "px";
if (all_p[i]["url"] == null) {
a.style.color = "#" + all_p[i]["txt_color"];
a.style.fontSize = all_p[i]["txt_fontSize"];
a.style.fontFamily = "Arial";
a.style.textAlign = "center"
}
parts_starting_z_index += i;
a.style.zIndex = parts_starting_z_index
}
}
var b = document.createElement("CANVAS");
document.getElementById("global_watch").appendChild(b);
if (typeof G_vmlCanvasManager != "undefined") {
b = G_vmlCanvasManager.initElement(b)
}
b.setAttribute("id", "regular_timepiece_canvas");
b.style.position = "absolute";
b.setAttribute("width", global_watch_p["width"]);
b.setAttribute("height", global_watch_p["height"]);
b.style.zIndex = parts_starting_z_index;
if (cyclop_mask_p["url"]) {
var b = document.createElement("CANVAS");
document.getElementById("global_watch").appendChild(b);
if (typeof G_vmlCanvasManager != "undefined") {
b = G_vmlCanvasManager.initElement(b)
}
b.setAttribute("id", "magnified_timepiece_canvas");
b.style.position = "absolute";
b.setAttribute("width", global_watch_p["width"]);
b.setAttribute("height", global_watch_p["height"]);
b.style.zIndex = parts_starting_z_index + 1
}
prepareTimepieceElementsIsDone = true
}
}
function placeCanvas(a, b, c) {
a.clearRect(-global_watch_p["width"], -global_watch_p["height"], global_watch_p["width"] * 2, global_watch_p["height"] * 2);
if (b == false) {} else {
a.save();
if (c) {
a.translate(global_watch_p[c["watch_x_center"]], global_watch_p[c["watch_y_center"]])
} else {
a.translate(global_watch_p["xcenter"], global_watch_p["ycenter"])
}
}
}
function updateDisplay() {
if (cyclop_mask_p["url"]) {
var a = document.getElementById("magnified_timepiece_canvas");
var b = a.getContext("2d");
placeCanvas(b, true);
drawTimepiece(b, true);
b.save();
b.translate(-global_watch_p["xcenter"], -global_watch_p["ycenter"]);
b.globalCompositeOperation = "destination-in";
b.drawImage(cyclop_mask_p["image"], 0, 0, cyclop_mask_p["width"], cyclop_mask_p["height"]);
b.restore();
b.restore()
}
var a = document.getElementById("regular_timepiece_canvas");
var b = a.getContext("2d");
placeCanvas(b, true);
drawTimepiece(b, false);
if (cyclop_mask_p["url"]) {
b.save();
b.translate(-global_watch_p["xcenter"], -global_watch_p["ycenter"]);
b.globalCompositeOperation = "destination-out";
b.drawImage(cyclop_mask_p["image"], 0, 0, cyclop_mask_p["width"], cyclop_mask_p["height"]);
b.restore()
}
b.restore()
}
function drawTimepiece(a, b) {
magnify_x_offset = 0;
magnify_y_offset = 0;
magnify_x_scale = 1;
magnify_y_scale = 1;
if (b == true) {
magnify_x_offset = cyclop_mask_p["xcenteroffset"];
magnify_y_offset = cyclop_mask_p["ycenteroffset"];
magnify_x_scale = cyclop_mask_p["xscale"];
magnify_y_scale = cyclop_mask_p["yscale"];
}
a.globalCompositeOperation = "source-over";
for (i = 0; i < all_parts.length; i++) {
var c = all_p[i];
a.save();
if (all_p[i]["update_mode"] != null) {
if (all_p[i]["update_mode"] == "monthdate") {
if (all_p[i]["url"] == null) {
document.getElementById(all_parts[i] + "_div").innerHTML = monthdate
} else {
document.getElementById(all_parts[i] + "_div").style.background = "url('" + image_folder + "num_" + monthdate + "." + all_p[i]["fileformat"] + "')"
}
} else if (all_p[i]["update_mode"] == "weekday") {
document.getElementById(all_parts[i] + "_div").style.background = "url('" + image_folder + "weekday_" + weekday_num + "." + all_p[i]["fileformat"] + "')"
} else {
a.translate(c["xcenteroffset"], c["ycenteroffset"]);
a.translate(magnify_x_offset, magnify_y_offset);
a.translate(c["offset_alternate_x_center"], c["offset_alternate_y_center"]);
a.scale(global_watch_p["xscale"] * magnify_x_scale, global_watch_p["yscale"] * magnify_y_scale);
a.rotate(display_calculation[c["update_mode"]]);
a.translate(-c["xrotation"], -c["yrotation"]);
a.drawImage(c["image"], 0, 0, c["width"], c["height"]);
for (var d in all_p[i]["__lightEffects"]) {
if (all_p[i]["__lightEffects"][d].height > 0) {
a.globalAlpha = getAlphaForRotation(d, display_calculation[c["update_mode"]], "normal");
a.drawImage(c["__lightEffects"][d], 0, 0, c["width"], c["height"])
}
}
}
} else {
a.translate(all_p[i]["xcenteroffset"], all_p[i]["ycenteroffset"]);
a.translate(-all_p[i]["xcenter"], -all_p[i]["ycenter"]);
a.drawImage(all_p[i]["image"], 0, 0, all_p[i]["width"], all_p[i]["height"])
}
a.restore()
}
}
function startWatchEngineWhenReady() {
if (all_p_to_be_loaded < 1) {
prepareTimepieceElements();
updateOnTimeDisplayOvertime()
} else {
requestAnimFrame(startWatchEngineWhenReady);
}
}
function startWatchEngine() {
if (window.addEventListener) {
window.addEventListener("load", function() {
startWatchEngineWhenReady()
}, false)
} else if (window.attachEvent) {
window.attachEvent("onload", function() {
startWatchEngineWhenReady()
})
}
}
function showStaticWatchOnTime() {
if (all_p_to_be_loaded < 1) {
prepareTimepieceElements();
setTimeToDefaultTime();
updateOnTimeDisplayOnce()
} else {
requestAnimFrame(showStaticWatchOnTime);
}
}
function spinToCurrentTimeAfterDelay(a) {}
var prepareTimepieceElementsIsDone = false;
var weekday_displayed = false;
var magnify_x_offset = 0;
var magnify_y_offset = 0